package com.iris.live.services.data.repositories.impl;

import com.google.common.base.Strings;
import com.iris.live.services.data.repositories.InvoiceRepository;
import com.iris.live.services.models.PageData;
import com.iris.live.services.services.InvoiceService;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by shixy on 2016/8/12.
 */
@Repository
@Transactional//(readOnly = true)
public class InvoiceRepositoryImpl extends BaseRepository implements InvoiceRepository {
    @Override
    public PageData getInvoiceFinancialOperationList(String permit,InvoiceService.GetInvoiceFinancialOperationListRequest request) {
        String sql = "select * from 财务操作 \n";
        sql += " where 1 = 1 \n";
        Map params = new HashMap();
        params.put("permit", permit);
        if (!Strings.isNullOrEmpty(request.target)){
            sql += " and 付款目的 = :target \n";
            params.put("target",request.target);
        }
        /*if (!Strings.isNullOrEmpty(request.saleType)){
            sql += " and 销售类型 = :saleType \n";
            params.put("saleType",request.saleType);
        }*/
        if (!Strings.isNullOrEmpty(request.carType)){
            sql += " and 意向车型 = :carType \n";
            params.put("carType",request.carType);
        }
        if (!Strings.isNullOrEmpty(request.status)){
            sql += " and 调车物流状态 = :status \n";
            params.put("status",request.status);
        }
        if (!Strings.isNullOrEmpty(request.vin)){
            sql += " and VIN = :vin \n";
            params.put("vin",request.vin);
        }
        /*if (!Strings.isNullOrEmpty(request.userName)){
            sql += " and 客户名称 like :userName \n";
            params.put("userName","%"+request.userName+"%");
        }*/
        return this.getPage(sql,params,request.getPageSize(),request.getPageIndex());
    }

    @Override
    public PageData getCollectionList(String permit,InvoiceService.getCollectionListRequest request) {
        String sql = "select * from 调出收款详单 \n";
        Map params = new HashMap();
        params.put("permit", permit);
        return this.getPage(sql,params,request.getPageSize(),request.getPageIndex());
    }

    @Override
    public PageData getPaymentList(String permit,InvoiceService.getPaymentListRequest request) {
        String sql = "select * from 调入付款详单 \n";
        Map params = new HashMap();
        params.put("permit", permit);
        return this.getPage(sql,params,request.getPageSize(),request.getPageIndex());
    }

    @Override
    public PageData getSaleCollectionList(String permit,InvoiceService.getSaleCollectionListRequest request) {
        String sql = "select * from 销售收款详单 \n";
        Map params = new HashMap();
        params.put("permit", permit);
        return this.getPage(sql,params,request.getPageSize(),request.getPageIndex());
    }
}
